﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Actuals.Business;
using Actuals.CoreDomain.Business;
using Actuals.CoreDomain.Data;
using Actuals.CoreDomain;
using Actuals.Common;

namespace Actuals
{
    public partial class ShowProjects : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {


                BindGridView();
            }

        }

        protected void gvResults_OnRowCommand(object sender, GridViewCommandEventArgs e)
        {
            string projectId;
            switch (e.CommandName)
            {
                case "EditProject":

                    projectId = e.CommandArgument.ToString();
                    ClientScript.RegisterStartupScript(this.GetType(), "UpdateAddProject", "UpdateAddProject(' " + projectId + " ');", true);
                    break;



            }
        }

        protected string getTeam(Object teamId)
        {
            IBusinessTeam businessTeam = new BusinessTeam();
            ITeam team = businessTeam.GetTeam(int.Parse(teamId.ToString()));
            return team.TeamDescription;
        }
        protected void BindGridView()
        {
            IBusinessProject businessProject = new BusinessProject();
            IList<IProject> projects = businessProject.GetProjects();

            gvResults.DataSource = projects;
            gvResults.DataBind();
        }

        protected void btnDeleteProject_Click(object sender, EventArgs e)
        {
            try
            {

                for (int i = 0; i < gvResults.Rows.Count; i++)
                {
                    CheckBox cb = (CheckBox)gvResults.Rows[i].FindControl("chkProject");
                    Label lbl = (Label)gvResults.Rows[i].FindControl("lblProjectId");

                    if (cb.Checked)
                    {
                        string projectId = string.Empty;
                        if (lbl != null)
                        {
                            projectId = lbl.Text;
                            IBusinessProject businessProject= new BusinessProject();
                            businessProject.DeleteProject(int.Parse(projectId));
                        }
                    }
                }

                lblMsg.Text = "Deleted";
                BindGridView();
            }
            catch (Exception ex)
            {
                lblMsg.Text = ex.Message;
            }
        }


    }
}